package com.world.rickcloudendpoint.service.net.session;

import com.world.rickcloudendpoint.common.IUpdatable;
import com.world.rickcloudendpoint.service.uuid.LongIdGenerator;
import io.netty.channel.Channel;
import lombok.extern.log4j.Log4j2;

/**
 * @description: 网络 tcp 的session
 * @author: jlsong
 * @date: 2021/12/24 21:08:36
 * @version: 1.0
 */
@Log4j2
public class TcpNetSession extends NetSession implements IUpdatable {

    private final long sessionId;

    /**
     * 消息发送
     */
    private TcpNetMessageSender tcpNetMessageSender;

    /**
     * 网络状态检查
     */
    private TcpNetStateUpdate tcpNetStateUpdate;

    /**
     * 网络消息切换开关，当玩家进入房间的时候，关闭开关，所有消息处理放入房间内，保证房间内协议处理单线程
     */
    private volatile boolean netMessageProcessSwitch = true;

    public TcpNetSession(Channel channel) {
        super(channel);
        LongIdGenerator longIdGenerator = new LongIdGenerator();
        sessionId = longIdGenerator.generateId();
        tcpNetMessageSender = new TcpNetMessageSender(this);
//        netProtoBufMessageProcess = new NetProtoBufMessageProcess(this);
        tcpNetStateUpdate = new TcpNetStateUpdate();
    }

    @Override
    public boolean update() {
//        processNetMessage(false);
        tcpNetStateUpdate.update();
        return false;
    }
}
